home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.6 KB | 94 lines | [TEXT/ttxt] |
- -- <<<-
-
- -- mausXing.sx
- -- Mouse Crossing Event example
- -- by Howard Metzenberg
- -- Kaleida ScriptX forever
- -- from "Events and Input Devices" chapter of
- -- ScriptX Components Guide
-
- -- This script demonstrates how to manage mouse-crossing events
-
- -- Note that this script has changed since ScriptX 1.0
- -- Now you must force focus on a presenter other than TextEdit
-
- module EventTest5 uses ScriptX end
- in module EventTest5
-
- -- first create a window with default settings
- object myWindow (Window)
- boundary:(new rect x2:600 y2:300)
- settings x:20, y:40
- end
- show myWindow
-
- global greenBrush := new Brush color:greenColor
- global redBrush := new Brush color:redColor
-
- class EnterPresenter(TwoDMultiPresenter)
- instance variables
- mci -- an interest in mouse crossing events
- instance methods
- method init self #rest args -> (
- apply nextMethod self args
- -- create a mouse crossing event and set its properties
- -- so that it can be used as an event interest
- self.mci := new MouseCrossingEvent
- self.mci.presenter := self
- self.mci.authorData := self
- self.mci.eventReceiver := colorme
- -- register it as an event interest
- addEventInterest(self.mci)
- )
- -- this method will receive mouse crossing events
- method colorme self match myEvent -> (
- if (myEvent.crossingType = @enter) then (
- self.fill := greenBrush -- green if you enter
- ) else (
- self.fill := redBrush -- red if you leave
- )
- print myEvent.crossingType
- @accept -- accept the event, since asynchronous
- )
- end
-
- -- make some overlapping presenters that will receive
- -- mouse crossing events and add them to the window
- object shape1 (EnterPresenter)
- boundary:(new rect x2:240 y2:260), stroke:blackBrush
- settings x:20, y:20
- end
- prepend myWindow shape1
- object shape2 (EnterPresenter)
- boundary:(new rect x2:340 y2:260), stroke:blackBrush
- settings x:240, y:20
- end
- prepend myWindow shape2
- object shape3 (EnterPresenter)
- boundary:(new rect x2:180 y2:140), stroke:blackBrush
- settings x:80, y:20
- end
- prepend myWindow shape3
- object shape4 (EnterPresenter)
- boundary:(new rect x2:180 y2:120), stroke:blackBrush
- settings x:240, y:20
- end
- prepend myWindow shape4
- object shape5 (EnterPresenter)
- boundary:(new rect x2:200 y2:120), stroke:blackBrush
- settings x:360, y:20
- end
- prepend myWindow shape5
-
- -- make one more to put inside the last one
- object insideShape (EnterPresenter)
- boundary:(new rect x2:100 y2:100), stroke:blackBrush
- settings x:100, y:50
- end
- -- put insideShape inside shape5 to show how
- -- mouse crossing events works with the presentation hierarchy
- -- note that it will be clipped by shape5
- prepend shape5 insideShape
-
- -- >>>
-